﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using CE.User;
using CE.Global;
using CE.Provider;

public partial class Provider_CarInsurance_ViewCarDrivingExperience : System.Web.UI.Page
{
    string PageName = "CXCI";
    string SubPageName = "CXCIDREXP"; 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null || Session[CE.Global.General.ProviderCompanyId] == null)
        {
            Response.Redirect("~/Provider/ProviderSecureLogin.aspx");
        }
        CheckMainPageAccess();
        CheckSubPageAccess();

        if (!IsPostBack)
        {
            LoadCarDrivingExpList();
        }
    }

    protected void grvCarDrivingExp_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (grvCarDrivingExp.Rows.Count > 0)
        {
            string strCUID = grvCarDrivingExp.SelectedDataKey.Values[0].ToString();
            Response.Redirect("ProviderCarDrivingExperience.aspx?CDEID=" + strCUID);
        }
    }

    public void LoadCarDrivingExpList()
    {
        CarDrivingExpDB _cardrivingexpdb = new CarDrivingExpDB();
        grvCarDrivingExp.DataSource = _cardrivingexpdb.GetProviderCarDrivingExpList(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId]));
        grvCarDrivingExp.DataBind();
    }

    protected void ibtBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/Provider/CarInsurance/TableMatching.aspx");
    }

    private void CheckMainPageAccess()
    {
        Int64 PageAccess = General.GetProviderMainPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), PageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
    }

    private void CheckSubPageAccess()
    {
        Int64 PageAccess = General.GetProviderSubPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), SubPageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
        else if (PageAccess == 100)
        {
            lnkNewCarDrivingExp.Visible = false;
        }
    }

}
